import Vue from 'vue'
import Vuex from 'vuex'
import { getItem}  from '@/utils/storage'
import { setItem  } from '../utils/storage'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // user:JSON.parse(window.localStorage.getItem('user'))  //当前登录的用户状态 存token等数据
    user: getItem('user')
  },
  mutations: {
    setUser(state ,data) {
      state.user = data
      //为了防止页面刷新数据丢失 ,我们还是需要本地存储,但是这里仅仅是为了 持久化而已
      // window.localStorage.setItem('user',JSON.stringify(state.user))
      setItem('user',data)
    }
  },
  actions: {
  },
  modules: {
  }
})
